/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAOHibernate;

import DAO.AlunoDAO;
import entidade.Aluno;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.Query;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Thais
 */
public class AlunoDAOHibernate implements AlunoDAO {

    @Override
    public List<Aluno> buscarPorNome(String nome) {

        List<Aluno> alunos = new ArrayList<Aluno>();
        Session session = null;
        Transaction transaction = null;
        try {
            session = HibernateUtil.getSessionfacotry().openSession();
            transaction = session.beginTransaction();
            Criteria consulta = session.createCriteria(Aluno.class);
           
                consulta.add(Restrictions.like("nome", "%" + nome + "%"));
            
            alunos = (List<Aluno>) consulta.list();
            transaction.commit();
        } catch (HibernateException e) {
            System.out.println("N‹o foi poss’vel insesirir o conf. Erro:" + e.getMessage());
        } finally {
            try {
                session.close();

            } catch (Throwable e2) {
                System.out.println("Erro ao fechar opera?‹o de inser?‹o. Mensagem: " + e2.getMessage());
            }
        }
        return alunos;
    }
}

